package com.xhs.open.util.json;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.xhs.common.util.json.GsonHelper;
import com.xhs.open.bean.XhsOpenComponentAccessToken;

import java.lang.reflect.Type;

public class XhsOpenComponentAccessTokenGsonAdapter implements JsonDeserializer<XhsOpenComponentAccessToken> {
  @Override
  public XhsOpenComponentAccessToken deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    XhsOpenComponentAccessToken componentAccessToken = new XhsOpenComponentAccessToken();
    JsonObject jsonObject = jsonElement.getAsJsonObject();
    componentAccessToken.setComponentAccessToken(GsonHelper.getString(jsonObject, "component_access_token"));
    componentAccessToken.setExpiresIn(GsonHelper.getPrimitiveInteger(jsonObject, "expires_in"));
    return componentAccessToken;
  }
}
